package com.jnshu.controller;

import com.jnshu.entity.Stu;
import com.jnshu.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

// controller :返回的数据经过视图解析器,进入相应的页面
// restController:返回的数据直接返回数据
@Controller
public class StuController {

    @Resource
    private StuService stuService;

    /**
     * 返回数据
     * @return
     */
    @RequestMapping("/query")
    @ResponseBody
    private List<Stu> queryStu(){
        List<Stu> list = stuService.query();
        return list;
    }

    /**
     * 经过视图解析器,进入index.jsp页面
     * @return
     */
    @RequestMapping("/queryModel")
    private ModelAndView queryModel(){
        ModelAndView mv = new ModelAndView("jsp/hello");
        return mv;
    }

    /**
     * 经过视图解析器,进入stuQuery.jsp页面
     * @return
     */
    @RequestMapping("/queryModelStu")
    private ModelAndView queryModelStu(){
        ModelAndView mv = new ModelAndView("stuQuery");
        mv.addObject("p",stuService.query());
        return mv;
    }

    /**
     * 返回内容
     * @return
     */
    @RequestMapping("/queryString")
    @ResponseBody
    private String queryStuString(){
        return "index";
    }
}

